#!/usr/bin/enr/python3
# -*- coding: utf-8 -*-
# -------------------------------
# @Author : hurong
# @File : 1105_p03面向对象.py
# @Time : 2023/11/16 22:44
# -------------------------------
a = 1
print(type(a))    # <class 'int'>

s = 'hello'
print(type(s))    # <class 'str'>

data = [1,2,3,4]
print(type(data))    # <class 'list'>

# 类定义
# 面向对象3大核心思想：继承、封装、多态
class MyClass:    # class MyClass(object) 类名后面不管是否写括号，都是继承根类
    pass

obj = MyClass()
print(obj)  # <__main__.MyClass object at 0x0000021B8BB73FD0>
print(type(obj))    # <class '__main__.MyClass'>
# 定义一个字符串的类
class MyString():

    # 初始化方法
    def __init__(self, name):
        # 初始化方法，自动调用
        # print("INIT run")
        self.name = name

    def upper(self):
        # 若需要引用初始化方法中的name,则需要通过self. 来引用
        print("upper" + self.name)


    def lower(self):
        print("lower" + self.name)

# 实例一个对象
ms1 = MyString("Tom")
ms2 = MyString("Jack")

# python 中的所有属性都是动态绑定的，如下40~42行代码
# ms1.name = 'Tom'
print(ms1.name)  # Tom
# print(ms2.name)
# '''Traceback (most recent call last):
#   File "D:\study\Huogewozi\git_prac\git-demo\pythonCode\1105_p03面向对象.py", line 41, in <module>
#     print(ms2.name)
# AttributeError: 'MyString' object has no attribute 'name'
# '''

print(ms1)    # <__main__.MyString object at 0x00000188DAE64FA0>
print(ms2)    # <__main__.MyString object at 0x00000188DAE64F70>

# 调用属性方法
ms1.lower()  # lower
ms2.lower()  # lower

ms1.upper()  # upper
ms2.upper()  # upper